package com.huluobo.a2205monthdemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.webkit.JavascriptInterface
import com.blankj.utilcode.util.SPUtils
import com.huluobo.a2205monthdemo.parking.ParkingActivity
import com.huluobo.a2205monthdemo.repair.RepairActivity
import com.huluobo.a2205monthdemo.sign.SignActivity
import com.huluobo.a2205monthdemo.sign.SignMonthActivity
import com.huluobo.a2205monthdemo.visitor.VisitorActivity
import com.huluobo.a2205monthdemo.x5.X5WebView
import com.huluobo.base.net.Const
import com.tencent.smtt.utils.s

class MainActivity : AppCompatActivity() {
    private val url: String = SPUtils.getInstance().getString(Const.PARAM_HOME)
    private lateinit var x5WebView: X5WebView
    private lateinit var listener: MainWebViewJavaScriptFun
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initWebView()
    }

    private fun initWebView() {
        listener = MainWebViewJavaScriptFun()
        x5WebView = findViewById(R.id.main_x5)
        x5WebView.loadUrl(url)
        x5WebView.view.overScrollMode = View.OVER_SCROLL_ALWAYS
        x5WebView.addJavascriptInterface(listener, "androidinfo")
    }

    inner class MainWebViewJavaScriptFun {

        @JavascriptInterface
        fun androidsign(id: String) {
            //打开签到activity
            start(SignActivity::class.java)
        }

        @JavascriptInterface
        fun androidaddculture(id: String) {
            //打开新闻activity
            Log.i("TagA", "新闻")
        }

        @JavascriptInterface
        fun androidparking(id: String?) {
            //车位申请
            start(ParkingActivity::class.java)
        }

        @JavascriptInterface
        fun androidapply(id: String?) {
            //我的申请
            Log.i("TagA", "我的申请")
        }

        @JavascriptInterface
        fun androidvisit(id: String?) {
            //来访预约
            start(VisitorActivity::class.java)
        }

        @JavascriptInterface
        fun androidpatrol(id: String?) {
            //巡更管理
            Log.i("TagA", "巡更管理")
        }

        @JavascriptInterface
        fun androidnews(id: String?) {
            Log.i("TagA", "新闻")
        }

        @JavascriptInterface
        fun androidnoticelist(id: String?) {
            Log.i("TagA", "通知")
        }

        @JavascriptInterface
        fun androidrepair(id: String?) {
            //维修管理
            start(RepairActivity::class.java)
        }

        @JavascriptInterface
        fun androidaddrepair(id: String?) {
            //添加维修
            Log.i("TagA", "添加维修")
        }

        @JavascriptInterface
        fun androidaddnotice(id: String?) {
            //公告管理
            Log.i("TagA", "添加公告")
        }

        @JavascriptInterface
        fun androidculture(id: String?) {
            //文化管理
            Log.i("TagA", "文化管理")
        }

        @JavascriptInterface
        fun androidnotice(id: String?) {
            //公告管理
            Log.i("TagA", "公告管理")
        }

        @JavascriptInterface
        fun androidattendance(id: String?) {
            //考勤管理
            start(SignMonthActivity::class.java)
        }

        @JavascriptInterface
        fun androidproperty(id: String?) {
            //物业审核
            Log.i("TagA", "物业审核")
        }

        @JavascriptInterface
        fun androidcheckculture(id: String?) {
            //文化审核
            Log.i("TagA", "文化审核")
        }

        @JavascriptInterface
        fun androidpeople(id: String?) {
            //人资管理
            Log.i("TagA", "人资管理")
        }
    }

    private fun start(clazz: Class<*>) {
        val intent = Intent(this, clazz)
        startActivity(intent)
    }
}